1333B - Kind Anton - CodeForces Solution


greedy implementation *1100

Please click on ads to support us..

Python Code:

for t in range(int(input())):
    n = int(input())

    a = list(map(int, input().split()))

    b = list(map(int, input().split()))

    s = set()

    for i in range(n):
        if (b[i] > a[i] and 1 not in s) or (b[i] < a[i] and -1 not in s):
            print('NO')
            break

        s.add(a[i])
    else:
        print('YES')

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mii map<int,int>
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define pob pop_back
#define mod 1000000007
#define inf 1e14
#define fr(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define frl(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define deb(x) cout<<#x<<x 
//bool present= binary_search(a.begin(),a.end(),4);
//auto it = lower_bound(a.begin(),a.end(),100);
//auto it = upperbound(a.begin(),a.end(),100);
void solve()
{
  int n,p=0,ne=0;
  cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++)
 { cin>>a[i];
  if(a[i]>0)
  p++;
  else
  if(a[i]<0)
  ne++;}
  for(int i=0;i<n;i++)
  cin>>b[i];
  for(int i=n-1;i>=0;i--)
  {
    long long int m=b[i]-a[i];
    if(a[i]>0)
    p--;
    else
    if(a[i]<0)
    ne--;
    if(m<0)
    {
        if(ne!=0) continue;
        else
        {
            cout<<"NO\n";
            return;
        }
    }
    else
    if(m>0)
    {
        if(p!=0) continue;
        else
        {
            cout<<"NO\n";
            return;
        }
    }

  }
  cout<<"YES\n";
  return;
}

int main()
{
int t; cin>>t;
while(t--)
solve();

return 0;
}


Comments

Submit
0 Comments
More Questions

1153A - Serval and Bus
1487C - Minimum Ties
1136A - Nastya Is Reading a Book
1353B - Two Arrays And Swaps
1490E - Accidental Victory
1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer